<?php

namespace admin\helper;

use admin\helper\ImageHander;
class upload{

    public function  uploadImg(){
        //上传图片
        $ret['state'] = 'FAIL';
        $rootPath = app_path."upload/";
        $path = 'origin/'. date('y-m-d',time()).'/';
        $uploadHandler = new \Sirius\Upload\Handler($rootPath.$path);
        $result = $uploadHandler->process($_FILES['upfile']);
        $fileName =  '/upload/'.$path.$result->name;
        if($fileName)
        {
            $result->confirm();
            $ret['size'] = $result->size;
            $ret['name'] = $result->name;
            $ret['type'] = $result->type;
            $ret['fileName'] = $fileName;
            $ret['original_name'] = $result->original_name;
            $ret['state'] = 'SUCCESS';
        }

        return $ret;
    }

    //加水印
    public function imgTxt($file,$txt){
        $rootPath = app_path."upload/watermark/";
        $path =  date('y-m-d',time()).'/';
        $img = new ImageHander($rootPath.$path,$txt);
        $files = $img->createImageMark(app_path.$file);
        return $files;

    }
}